package ggze.GGZEServer.home.controller;

import ggze.GGZEServer.home.service.GGZEServerCommonService;
import ggze.tool.BeanToJson;
import ggze.tool.ReturnBody;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("CommonController")
public class CommonController {
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private GGZEServerCommonService ggzeServerCommonService;
    //获得导航
    @RequestMapping(value = "GetNavigatin",method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public String GetNavigatin(@RequestBody JSONObject jsonObject){
        ReturnBody returnBody = new ReturnBody();
        try {
            JSONArray array  = ggzeServerCommonService.getNav(jsonObject.getString("userID"));
            returnBody.setCode("0");
            returnBody.setData(BeanToJson.toJsonArrayString(array));
        }catch (Exception e){
            returnBody.setCode("1");
        }
        return BeanToJson.toJsonObjectString(returnBody);
    }

    //登录
    @RequestMapping(value = "LoginSql",method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public String LoginSql(@RequestBody JSONObject jsonObject){
        ReturnBody returnBody = new ReturnBody();
        try {
            returnBody  = ggzeServerCommonService.loginSql(jsonObject);
        }catch (Exception e){
            returnBody.setCode("1");
        }
        return BeanToJson.toJsonObjectString(returnBody);
    }

    //获得ip
    @RequestMapping(value = "CheckIp",method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public String CheckIp(@RequestBody JSONObject jsonObject){
        ReturnBody returnBody = new ReturnBody();
        try {
            returnBody  = ggzeServerCommonService.checkIp(jsonObject);
        }catch (Exception e){
            returnBody.setCode("1");
        }
        return BeanToJson.toJsonObjectString(returnBody);
    }

    //用户注册
    @RequestMapping(value = "Regist",method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public String Regist(@RequestBody JSONObject jsonObject){
        ReturnBody returnBody = new ReturnBody();
        try {
            returnBody  = ggzeServerCommonService.regist(jsonObject);
        }catch (Exception e){
            returnBody.setCode("1");
        }
        return BeanToJson.toJsonObjectString(returnBody);
    }

    //用户启用/禁用
    @RequestMapping(value = "Status",method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public String Status(@RequestBody JSONObject jsonObject){
        ReturnBody returnBody = new ReturnBody();
        try {
            returnBody  = ggzeServerCommonService.bind(jsonObject);
        }catch (Exception e){
            returnBody.setCode("1");
        }
        return BeanToJson.toJsonObjectString(returnBody);
    }


    @RequestMapping(value = "RoleAU",method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public String RoleAU(@RequestBody JSONObject jsonObject){
        ReturnBody returnBody = new ReturnBody();
        try {
            returnBody  = ggzeServerCommonService.roleAdd(jsonObject);
        }catch (Exception e){
            returnBody.setCode("1");
        }
        return BeanToJson.toJsonObjectString(returnBody);
    }

    @RequestMapping(value = "RoleData",method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public String RoleData(@RequestBody JSONObject jsonObject){
        ReturnBody returnBody = new ReturnBody();
        try {
            returnBody  = ggzeServerCommonService.roleStateData(jsonObject);
        }catch (Exception e){
            returnBody.setCode("1");
        }
        return BeanToJson.toJsonObjectString(returnBody);
    }
    @RequestMapping(value = "RoleLook",method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public String RoleLook(@RequestBody JSONObject jsonObject){
        ReturnBody returnBody = new ReturnBody();
        try {
            returnBody  = ggzeServerCommonService.roleStateLook(jsonObject);
        }catch (Exception e){
            returnBody.setCode("1");
        }
        return BeanToJson.toJsonObjectString(returnBody);
    }
    @RequestMapping(value = "RoleNavig",method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public String RoleNavig(@RequestBody JSONObject jsonObject){
        ReturnBody returnBody = new ReturnBody();
        try {
            returnBody  = ggzeServerCommonService.roleStateNavig(jsonObject);
        }catch (Exception e){
            returnBody.setCode("1");
        }
        return BeanToJson.toJsonObjectString(returnBody);
    }

}
